IF OBJECT_ID('ssf.utl_string_count_occurrences') IS NOT NULL
	DROP FUNCTION ssf.utl_string_count_occurrences;
GO

CREATE FUNCTION ssf.utl_string_count_occurrences (
	@string VARCHAR(MAX)
	, @separator VARCHAR(64)
)
RETURNS TABLE
AS
RETURN (
	SELECT (DATALENGTH(@string) - DATALENGTH(REPLACE(@string, @separator, ''))) / ISNULL(NULLIF(DATALENGTH(@separator), 0), 1)AS occurrences
);
GO
